import { Component, OnInit, Output,EventEmitter} from '@angular/core';
import {fadeIn} from "../../../../../animate";

@Component({
  selector: 'app-add-module',
  templateUrl: './add-module.component.html',
  styleUrls: ['./add-module.component.css'],
   animations:[fadeIn]
})
export class AddModuleComponent implements OnInit {
  @Output() onCloseAdd = new EventEmitter<boolean>();
 addModule = {
   packageArr:[{
     isSelect:true
   }],
   isSelectAll:false,//是否全选
   isClose:false,//关闭窗口
   selectAll:function (type) {
     this.isSelectAll = !this.isSelectAll;
     if (this.isSelectAll) {
       this.packageArr.forEach((item) => {
         if (!item.isSelect) {
           item.isSelect = true;
         }
       })
     } else {
       this.packageArr.forEach((item) => {
         if (item.isSelect) {
           item.isSelect = false;
         }
       })
     }
   },
   selectSingle:function (index) {
     this.packageArr[index].isSelect = !this.packageArr[index].isSelect;
     for(let i = 0;i<this.packageArr.length;i++){
       if (!this.packageArr[i].isSelect){
         this.isSelectAll = false;
       }
     }
   }
 };
  constructor(

  ) { }

  ngOnInit() {
    for(let i =0;i<4;i++){
      this.addModule.packageArr.push({isSelect:false});
    }
  }
  onClose () {
    this.onCloseAdd.emit(this.addModule.isClose);
  }
}
